<template>
  <div class="bigbox">
    <!-- 表头盒子 -->
    <div class="leftbox">
      <!-- 树节点过滤 -->
      <div>
        <el-input
          placeholder="输入关键字进行过滤"
          size="small"
          v-model="filterText"
        >
        </el-input>
      </div>
      <!-- 树组件 -->
      <div style="margin-top: 15px">
        <el-tree
          ref="tree"
          :props="props"
          :highlight-current="true"
          @node-click="handleNodeClick"
          :filter-node-method="filterNode"
          :default-checked-keys="[0]"
          :load="loadNode"
          node-key="domainId"
          lazy
        >
          <span slot-scope="{ node }" class="slot-t-node">
            <template>
              <!-- <img
                class="node-img"
                v-if="data.bizOrgType == '03' || data.bizOrgType == '30'"
                src="../../assets/node0.png"
              />
              <img
                class="node-img"
                v-if="data.bizOrgType == '04' || data.bizOrgType == '40'"
                src="../../assets/node1.png"
              /> -->
              <span :style="{ 'font-size': '14px' }">{{ node.label }}</span>
            </template>
          </span>
        </el-tree>
      </div>
    </div>
    <!-- 盒子主体 -->
    <div class="mainbox">
      <div class="top">
        <div class="search">
          <el-input
            placeholder="请输入关键字搜索"
            prefix-icon="el-icon-search"
            v-model="inputValue"
          >
          </el-input>
        </div>
        <div class="towBtn">
          <button @click="chongzhi" class="button">重置</button>
          <button @click="chaxun" class="button chaxun">查询</button>
        </div>
      </div>
      <div class="bodybox">
        <!-- 新增按钮 -->
        <!-- 循环图片盒子 -->
        <div class="table" v-if="domainType !== 'Root'">
          <div class="titlebox">
            <div class="text"></div>
            <div
              class="right"
              :style="{ alignItems: 'center', lineHeight: '32.5px' }"
            >
              <button
                v-if="this.domainType === '0' || this.domainType === '1'"
                type="primary"
                size="small"
                class="bewdao daochu"
                @click="submit('add')"
              >
                <i style="margin-left: 0px" class="el-icon-plus"></i>新增
              </button>
              <el-tooltip
                class="item"
                effect="dark"
                content="刷新"
                placement="top"
              >
                <span
                  @click="shuaxin"
                  :style="{ cursor: 'pointer', fontSize: '20px' }"
                  ><i class="el-icon-refresh-right"></i
                ></span>
              </el-tooltip>
              <el-dropdown trigger="click" @command="command">
                <span class="el-dropdown-link">
                  <el-tooltip
                    class="item"
                    effect="dark"
                    content="密度"
                    placement="top"
                  >
                    <span :style="{ cursor: 'pointer', fontSize: '20px' }"
                      ><i class="el-icon-d-caret"></i
                    ></span>
                  </el-tooltip>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item class="dropdown-list" command="默认"
                    >默认</el-dropdown-item
                  >
                  <el-dropdown-item class="dropdown-list" command="中等"
                    >中等</el-dropdown-item
                  >
                  <el-dropdown-item class="dropdown-list" command="紧凑"
                    >紧凑</el-dropdown-item
                  >
                </el-dropdown-menu>
              </el-dropdown>
            </div>
          </div>
          <el-table
            v-loading="loading"
            :data="tableData"
            style="width: 100%"
            border
            height="77vh"
            id="exportTabyong"
            ref="table"
            :size="iissize"
            :header-cell-style="{
              background: '#f5f5f5',
              'text-align': 'center',
            }"
          >
            <template slot="empty">
              <el-empty description="暂无数据"></el-empty>
            </template>
            <!-- <el-table-column
              align="center"
              type="index"
              width="50"
              label="序号"
            >
            </el-table-column> -->
            <el-table-column align="left" prop="classCode" label="类编码">
            </el-table-column>
            <el-table-column align="left" prop="className" label="类名称">
            </el-table-column>
            <el-table-column
              align="left"
              prop="parentClassName"
              label="父类名称"
            >
            </el-table-column>
            <el-table-column
              width="100px"
              align="center"
              prop="hasTable"
              label="是否建表"
            >
              <template slot-scope="scope">
                <span>{{ scope.row.hasTable ? "是" : "否" }}</span>
              </template>
            </el-table-column>
            <el-table-column
              width="100px"
              align="center"
              prop="canInstance"
              label="可实例化"
            >
              <template slot-scope="scope">
                <span>{{ scope.row.canInstance ? "是" : "否" }}</span>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              width="100px"
              prop="classImageBase64"
              label="图标"
            >
              <template slot-scope="scope">
                <img
                  v-if="scope.row.classImageBase64"
                  :src="'data:image/png;base64,' + scope.row.classImageBase64"
                  style="width: 16px; height: 16px"
                />
              </template>
            </el-table-column>
            <el-table-column width="300px" align="center" label="操作">
              <template slot-scope="scope">
                <div class="table-cz">
                  <el-tooltip
                    class="item"
                    effect="dark"
                    content="类属性维护"
                    placement="top"
                  >
                    <img
                      style="width: 14px; height: 14px; cursor: pointer"
                      src="@/assets/image/Device-all/maintain.png"
                      @click="classMaintain(scope.row)"
                  /></el-tooltip>
                  <el-tooltip
                    class="item"
                    effect="dark"
                    content="储存表维护"
                    placement="top"
                  >
                    <img
                      style="width: 14px; height: 14px; cursor: pointer"
                      src="@/assets/image/jb.png"
                      @click="StorageTable(scope.row)"
                  /></el-tooltip>
                  <el-tooltip
                    class="item"
                    effect="dark"
                    content="类关系维护"
                    placement="top"
                  >
                    <img
                      style="width: 14px; height: 14px; cursor: pointer"
                      src="@/assets/image/Device-all/lgx.png"
                      @click="Relation(scope.row)"
                  /></el-tooltip>
                  <el-tooltip
                    class="item"
                    effect="dark"
                    content="视图管理"
                    placement="top"
                  >
                    <img
                      style="width: 16px; height: 16px; cursor: pointer"
                      src="@/assets/image/Device-all/view.png"
                      @click="View(scope.row)"
                  /></el-tooltip>
                  <el-tooltip
                    class="item"
                    effect="dark"
                    content="子菜单"
                    placement="top"
                  >
                    <el-dropdown
                      trigger="click"
                      placement="bottom"
                      @command="handleCommand"
                    >
                      <img
                        style="width: 14px; height: 14px; cursor: pointer"
                        src="@/assets/image/Device-all/menu.png"
                      />
                      <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item
                          :command="{ type: 'edit', value: scope.row }"
                          ><i
                            style="
                              font-size: 14px;
                              color: rgb(64, 149, 229);
                              cursor: pointer;
                            "
                            class="el-icon-edit"
                          ></i
                          >修改</el-dropdown-item
                        >
                        <el-dropdown-item
                          :command="{ type: 'delete', value: scope.row }"
                          ><i
                            style="font-size: 14px; color: red; cursor: pointer"
                            class="el-icon-delete"
                          ></i
                          >删除</el-dropdown-item
                        >
                        <el-dropdown-item
                          :command="{
                            type: 'move',
                            value: scope.row,
                            statu: 'up',
                          }"
                          ><i
                            style="
                              font-size: 14px;
                              color: rgb(64, 149, 229);
                              cursor: pointer;
                            "
                            class="el-icon-upload2"
                          ></i
                          >上移</el-dropdown-item
                        >
                        <el-dropdown-item
                          :command="{
                            type: 'move',
                            value: scope.row,
                            statu: 'down',
                          }"
                          ><i
                            style="
                              font-size: 14px;
                              color: rgb(64, 149, 229);
                              cursor: pointer;
                            "
                            class="el-icon-download"
                          ></i
                          >下移</el-dropdown-item
                        >
                      </el-dropdown-menu>
                    </el-dropdown>
                  </el-tooltip>
                </div>
              </template>
            </el-table-column>
          </el-table>
          <!-- <el-pagination
            background
            class="pagination"
            layout="prev, pager, next"
            :current-page.sync="pageobj._pageNo"
            @current-change="chaxun"
            :total="total"
          >
          </el-pagination> -->
        </div>
        <!-- 新增/修改弹框 -->
        <el-dialog
          :show-close="true"
          :visible.sync="dialogVisible"
          v-if="dialogVisible"
          width="500px"
          :close-on-click-modal="false"
          :destroy-on-close="true"
          :before-close="diaClose"
          :center="true"
        >
          <div class="dialog">
            <!-- 企业下拉 -->
            <el-form
              ref="dialogForm"
              :rules="isedit === 'add' ? rules : rules1"
              :model="dialogForm"
              label-width="110px"
            >
              <el-form-item
                label="父类"
                v-if="isedit === 'add'"
                prop="parentId"
              >
                <el-select v-model="dialogForm.parentId" placeholder="请选择">
                  <el-option
                    v-for="item in parentList"
                    :key="item.value"
                    :label="item.text"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="类编码" prop="classCode">
                <el-input
                  v-model="dialogForm.classCode"
                  :disabled="isedit === 'edit'"
                ></el-input>
              </el-form-item>
              <el-form-item label="类名称" prop="className">
                <el-input v-model="dialogForm.className"></el-input>
              </el-form-item>
              <el-form-item label="类说明" prop="classExplain">
                <el-input
                  v-model="dialogForm.classExplain"
                  type="textarea"
                  :rows="4"
                  resize="none"
                ></el-input>
              </el-form-item>
              <el-form-item
                v-if="isedit === 'add'"
                label="可实例化"
                prop="canInstance"
              >
                <el-switch
                  v-model="dialogForm.canInstance"
                  active-color="#13ce66"
                  inactive-color="#efefef"
                >
                </el-switch>
              </el-form-item>
              <el-form-item
                v-if="isedit === 'add'"
                label="继承分组"
                prop="extendGroup"
              >
                <el-switch
                  v-model="dialogForm.extendGroup"
                  active-color="#13ce66"
                  inactive-color="#efefef"
                >
                </el-switch>
              </el-form-item>
              <el-form-item label="类图标" prop="classImage">
                <el-upload
                  class="avatar-uploader"
                  v-model="dialogForm.imageBase64"
                  action="https://jsonplaceholder.typicode.com/posts/"
                  :show-file-list="false"
                  :http-request="httpRequest"
                >
                  <img
                    v-if="imageUrl"
                    :src="imageUrl"
                    class="avatar"
                    style="margin-top: 10px"
                  />
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
              </el-form-item>
            </el-form>
            <!-- 弹窗内容 -->
          </div>
          <div style="margin-top: 10px; text-align: center">
            <span slot="footer" class="dialog-footer">
              <el-button @click="diaClose">取 消</el-button>
              <el-button type="primary" @click="add">确 定</el-button>
            </span>
          </div>
        </el-dialog>
        <el-dialog
          :show-close="true"
          :visible.sync="MaintainVisible"
          width="1500px"
          :close-on-click-modal="false"
          :destroy-on-close="true"
          :before-close="diaClose"
          :center="true"
        >
          <ClassMaintain v-if="MaintainVisible" :classData="classData" />
        </el-dialog>
        <el-dialog
          :show-close="true"
          :visible.sync="StorageVisible"
          :width="storageWidth"
          :close-on-click-modal="false"
          :destroy-on-close="true"
          :before-close="diaClose"
          append-to-body
          :center="true"
        >
          <!-- 企业下拉 -->
          <div v-if="storageWidth === '500px' && StorageVisible">
            <el-form
              ref="tableForm"
              :rules="tableRules"
              :model="dialogForm"
              label-width="110px"
            >
              <el-form-item label="表编码" prop="tableCode">
                <el-input v-model="dialogForm.tableCode"></el-input>
              </el-form-item>
              <el-form-item label="表名称" prop="tableName">
                <el-input v-model="dialogForm.tableName"></el-input>
              </el-form-item>
              <el-form-item label="数据库" prop="tableOwner">
                <el-select v-model="dialogForm.tableOwner">
                  <el-option
                    v-for="item in databaseList"
                    :key="item.value"
                    :label="item.text"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="表说明" prop="tableExplain">
                <el-input
                  v-model="dialogForm.tableExplain"
                  type="textarea"
                  :rows="4"
                  resize="none"
                ></el-input>
              </el-form-item>
            </el-form>
            <!-- 弹窗内容 -->
            <div style="margin-top: 10px; text-align: center">
              <span slot="footer" class="dialog-footer">
                <el-button @click="diaClose">取 消</el-button>
                <el-button type="primary" @click="tableSubmit">保 存</el-button>
              </span>
            </div>
          </div>
          <TableMaintain
            v-else-if="storageWidth === '1500px' && StorageVisible"
            :storageData="storageData"
          ></TableMaintain>
        </el-dialog>
        <el-dialog
          :show-close="true"
          :visible.sync="RelationVisible"
          width="1000px"
          top="5vh"
          :close-on-click-modal="false"
          :destroy-on-close="true"
          :before-close="diaClose"
          append-to-body
          :center="true"
        >
          <RelationTable
            v-if="RelationVisible"
            :addType="'up'"
            :relationData="relationData"
          ></RelationTable>
          <div style="height: 20px"></div>
          <RelationTable
            v-if="RelationVisible"
            :addType="'down'"
            :relationData="relationData"
          ></RelationTable>
        </el-dialog>
        <nt-dialog
          :visible.sync="viewVisible"
          v-if="viewVisible"
          width="1500px"
          @diaClose="diaClose"
        >
          <Device-view :viewData="viewData"></Device-view>
        </nt-dialog>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getRootDomainListApi,
  getChildDomainListApi
} from '@/api/Device-all/Device-domain'
import {
  addModelClassApi,
  addTableApi,
  delModelClassApi,
  // delModelClassApi,
  downClassApi,
  editClassApi,
  getClassDataApi,
  getDatabaseListApi,
  getModelClassListApi,
  getParentListApi,
  upClassApi
} from '@/api/Device-all/Device-model'
import ClassMaintain from './components/ClassMaintain.vue'
import TableMaintain from './components/TableMaintain.vue'
import RelationTable from './components/RelationTable.vue'
import NtDialog from '@/components/nt-dialog.vue'
import DeviceView from '../Device-view/index.vue'
export default {
  name: 'DeviceModel',
  components: {
    ClassMaintain,
    TableMaintain,
    RelationTable,
    NtDialog,
    DeviceView
  },
  data () {
    return {
      // list: [
      //   {
      //     domainName: '模型定义',
      //     domainId: 0,
      //     domainType: 'Root',
      //     parentId: null
      //   }
      // ],
      storageWidth: '500px',
      imageUrl: '',
      filterText: '',
      inputValue: '',
      domainId: '',
      domainType: '',
      parentId: '',
      node: null,
      diaTime: '',
      timeType: true,
      tableData: [],
      loading: false,
      iissize: 'medium',
      classData: {},
      storageData: {},
      relationData: {},
      dialogForm: {},
      viewData: {},
      parentList: [],
      rules: {
        classCode: [
          { required: true, message: '请输入类编码', trigger: 'blur' }
        ],
        className: [
          { required: true, message: '请输入类名称', trigger: 'blur' }
        ],
        canInstance: [
          { required: true, message: '请选择是否可实例化', trigger: 'change' }
        ],
        extendGroup: [
          { required: true, message: '请选择是否继承分组', trigger: 'change' }
        ]
      },
      tableRules: {
        tableCode: [
          { required: true, message: '请输入表编码', trigger: 'blur' }
        ],
        tableName: [
          { required: true, message: '请输入表名称', trigger: 'blur' }
        ],
        tableOwner: [
          { required: true, message: '请选择数据库', trigger: 'change' }
        ]
      },
      rules1: {
        classCode: [
          { required: true, message: '请输入类编码', trigger: 'blur' }
        ],
        className: [
          { required: true, message: '请输入类名称', trigger: 'blur' }
        ]
      },
      databaseList: [],
      deflist: [],
      props: {
        label: 'domainName'
      },
      dialogVisible: false,
      MaintainVisible: false,
      StorageVisible: false,
      RelationVisible: false,
      isedit: 'add',
      // pageobj: {
      //   _pageNo: 0,
      //   _pageSize: 15,
      // },
      // total: 0,
      viewVisible: false
    }
  },
  watch: {
    filterText (val) {
      this.$refs.tree.filter(val)
    }
  },
  created () {
    this.getDatabaseList()
  },
  async mounted () {
    await this.getRootDomainList()
    this.refreshNode(100)
    this.$refs.tree.setCurrentKey(100)
    this.domainType = this.tableData[0].domainType
    this.domainId = this.tableData[0].domainId
    this.getModelClassList(this.domainId)
  },
  methods: {
    async getDatabaseList () {
      const res = await getDatabaseListApi()
      this.databaseList = res.data.list
    },
    handleCommand (obj) {
      if (obj.type === 'edit') {
        this.edit(obj.value)
      } else if (obj.type === 'delete') {
        this.del(obj.value)
      } else if (obj.type === 'move') {
        this.move(obj.statu, obj.value)
      }
    },
    httpRequest (data) {
      this.imageUrl = URL.createObjectURL(data.file)
      console.log('this.imageUrl', this.imageUrl)
      // 这是限制上传文件类型
      const isPFX = data.file.type === 'image/png'
      const isLt2M = data.file.size / 1024 / 1024 < 2
      if (!isPFX) {
        this.$message.error('上传头像图片只能是PNG格式!')
      } else if (!isLt2M) {
        this.$message.error('上传文件大小不能超过 2MB!')
      } else {
        this.getBase64(data.file).then((resBase64) => {
          this.dialogForm.classImage = resBase64.split(',')[1] // 直接拿到base64信息
        })
      }
    },
    getBase64 (file) {
      return new Promise((resolve, reject) => {
        const reader = new FileReader()
        let fileResult = ''
        reader.readAsDataURL(file)
        // 开始转
        reader.onload = function () {
          fileResult = reader.result
        }
        // 转 失败
        reader.onerror = function (error) {
          reject(error)
        }
        // 转 结束  就 resolve 出去
        reader.onloadend = function () {
          resolve(fileResult)
        }
      })
    },
    async getRootDomainList () {
      this.loading = true
      const res = await getRootDomainListApi()
      this.deflist = res.data.list
      this.tableData = res.data.list
      this.loading = false
    },
    // 获取模型类列表
    async getModelClassList (id) {
      // if (this.domainType !== '1') return
      this.loading = true
      const res = await getModelClassListApi(id)
      console.log(res)
      this.deflist = res.data.list
      this.tableData = res.data.list
      this.loading = false
    },
    async getParentList (id) {
      const res = await getParentListApi(id)
      this.parentList = res.data.list
    },
    // 新增弹窗
    submit (val) {
      this.isedit = val
      if (this.isedit === 'add') {
        // this.dialogForm.extendGroup = false
        // this.dialogForm.canInstance = false
        // this.dialogForm.domainId = this.domainId
        this.$set(this.dialogForm, 'extendGroup', false)
        this.$set(this.dialogForm, 'canInstance', false)
        this.$set(this.dialogForm, 'domainId', this.domainId)
      }
      this.getParentList(this.domainId)
      this.dialogVisible = true
    },
    // 类属性维护弹窗
    classMaintain (item) {
      console.log('item', item)
      this.classData = item
      this.MaintainVisible = true
    },
    // 储存表弹窗
    async StorageTable (item) {
      console.log(item)
      if (!item.hasTable) {
        this.storageWidth = '500px'
        this.dialogForm.classId = item.classId
        this.$set(this.dialogForm, 'tableOwner', this.databaseList[0].value)
      } else {
        this.storageWidth = '1500px'
        this.storageData = item
      }
      this.StorageVisible = true
    },
    // 类关系弹窗
    Relation (item) {
      this.relationData = item
      this.RelationVisible = true
    },
    View (item) {
      console.log(item)
      this.viewData = item
      this.viewVisible = true
    },
    diaClose () {
      this.dialogVisible = false
      this.MaintainVisible = false
      this.RelationVisible = false
      this.StorageVisible = false
      this.viewVisible = false
      this.dialogForm = {}
    },
    shuaxin () {
      if (!this.domainType) return
      if (this.domainType === '1' || this.domainType === '0') {
        this.getModelClassList(this.domainId)
        // this.refreshNode(this.node.key)
      } else {
        // this.getRootDomainList()
        // this.refreshNode(this.node.key)
      }
      this.$message({
        type: 'success',
        message: '列表刷新成功',
        duration: 2000
      })
    },
    // 导出

    // 查询分页信息
    async chaxun () {
      const list = [...this.deflist]
      if (this.inputValue) {
        this.tableData = list.filter((item) =>
          Object.values(item).includes(this.inputValue)
        )
      } else {
        this.tableData = [...list]
      }
    },
    command (val) {
      if (val === '默认') {
        this.iissize = 'medium'
      } else if (val === '中等') {
        this.iissize = 'small'
      } else {
        this.iissize = 'mini'
      }
    },
    refreshNode (key) {
      console.log('key', key)
      // 获取当前节点，key可以在@node-click和:load绑定函数的回调参数node用变量存储后有需要刷新的地方取node.key
      const node = this.$refs.tree.getNode(key)
      console.log('node', node)
      //  设置未进行懒加载状态
      node.loaded = false
      // 重新展开节点就会间接重新触发load达到刷新效果
      this.$nextTick(() => {
        node.expand()
      })
    },
    // 树节点点击
    async handleNodeClick (val, node) {
      console.log(val)
      this.node = node
      console.log('node', this.node)
      // if (val.domainType === 'Root') {
      //   this.domainId = val.domainId
      //   this.domainType = val.domainType
      //   // this.getRootDomainList()
      // } else {
      this.domainId = val.domainId
      this.domainType = val.domainType
      this.parentId = val.parentId
      this.getModelClassList(val.domainId)
      // }
    },
    // 树组件懒加载
    async loadNode (node, resolve) {
      // if (node.level === 0) {
      //   // 初始的级数（最顶层）
      //   return resolve(this.list) // 最顶层数据渲染为region
      // }
      if (node.level === 0) {
        const res = await getRootDomainListApi()
        return resolve(res?.data.list)
      } else if (node.level > 0) {
        const res = await getChildDomainListApi(node.data.domainId)
        return resolve(res?.data.list)
      } else {
        return resolve([])
      }
    },
    // 树节点过滤
    filterNode (value, data) {
      if (!value) return true
      return data.domainName.indexOf(value) !== -1
    },
    // 表新增
    async tableSubmit () {
      await this.$refs.tableForm.validate()
      const res = await addTableApi(this.dialogForm)
      if (res.code == 200) {
        this.$message.success(res.message)
        this.getModelClassList(this.domainId)
        this.diaClose()
      } else {
        this.$message.success(res.message)
      }
    },
    // 新增保存/修改
    async add () {
      await this.$refs.dialogForm.validate()
      console.log(this.dialogForm)
      if (this.isedit === 'add') {
        const res = await addModelClassApi(this.dialogForm)
        if (res.code == 200) {
          this.$message.success(res.message)
          this.getModelClassList(this.domainId)
        } else {
          this.$message.success(res.message)
        }
      } else if (this.isedit === 'edit') {
        const res = await editClassApi(this.dialogForm)
        console.log(res)
        this.$message.success(res.message)
        this.getModelClassList(this.domainId)
        this.refreshNode(this.node.key)
      }
      this.diaClose()
    },
    // 移动
    async move (type, item) {
      this.$confirm('此操作将移动模型类, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          const res =
            type === 'up'
              ? await upClassApi({ classId: item.classId })
              : await downClassApi({ classId: item.classId })
          console.log(res)
          if (res.code == 200) {
            this.$message.success(res.message)
          } else {
            this.$message(res.message)
          }
          if (this.domainType === '1' || this.domainType === '0') {
            this.getModelClassList(this.domainId)
            // this.refreshNode(this.node.key)
          } else {
            // this.getRootDomainList()
            // this.refreshNode(this.node.key)
          }
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消移动'
          })
        })
    },
    // 编辑
    async edit (item) {
      this.isedit = 'edit'
      const res = await getClassDataApi(item.classId)
      // console.log(res)
      const data = res.data.entity
      this.dialogForm = {
        classCode: data.classCode,
        className: data.className,
        classImage: data.classImageBase64,
        classId: data.classId,
        classExplain: data.classExplain
      }
      this.imageUrl = data.classImageBase64
        ? 'data:image/png;base64,' + data.classImageBase64
        : ''
      // console.log('imageUrl', this.dialogForm)
      this.$forceUpdate()
      this.dialogVisible = true
    },
    // 删除
    async del (item) {
      console.log(item)
      this.$confirm('此操作将永久删除该模型类, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          try {
            const res = await delModelClassApi(item.classId)
            if (res.code == 200) {
              this.$message.success('删除成功')
              this.getModelClassList(this.domainId)
            } else {
              this.$message.success(res.message)
            }
          } catch (e) {
            console.log(e)
          }
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    chongzhi () {
      this.inputValue = ''
      if (this.domainType === '1' || this.domainType === '0') {
        this.getModelClassList(this.domainId)
        // this.refreshNode(this.node.key)
      } else {
        // this.getRootDomainList()
        // this.refreshNode(this.node.key)
      }
    },
    // 图片上传成功
    handleAvatarSuccess (res, file) {
      this.dialogForm.imageUrl = URL.createObjectURL(file.raw)
    },
    beforeAvatarUpload (file) {
      const isJPG = file.type === 'image/jpeg'
      const isLt2M = file.size / 1024 / 1024 < 2

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!')
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!')
      }
      return isJPG && isLt2M
    }
  }
}
</script>

<style lang="scss" scoped>
*{
  box-sizing: border-box;
}
.table-cz {
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 40px;
  height: 40px;
  line-height: 40px;
  border: 1px solid #d9d9d9;
  text-align: center;
}
.avatar {
  width: 40px;
  height: 40px;
  display: block;
}
.dialog-footer {
  display: flex;
  justify-content: center;
}
.bigbox {
  background-color: #f1f1f1;
  height: 100%;
  padding: 9px;
  display: flex;
  .leftbox {
    width: 300px;
    height: 100%;
    overflow: auto;
    background-color: #fff;
    padding: 20px;
  }
  .mainbox {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-left: 10px;
    .top {
      padding: 0 40px;
      display: flex;
      justify-content: space-between;
      width: 100%;
      min-height: 80px;
      background-color: #fff;
      border-bottom: 1px solid #f1f1f1;
      margin-bottom: 10px;
      align-items: center;
      .search {
        display: flex;
        align-items: center;
        width: 400px;
      }
    }
    .bodybox {
      position: relative;
      background-color: #fff;
      padding: 20px;
      padding-bottom: 30px;
      flex: 1;
      // min-height: 87.6vh;
      .pagination {
        position: absolute;
        right: 20px;
        bottom: 10px;
      }
      .table {
        .titlebox {
          display: flex;
          justify-content: space-between;
          margin-bottom: 10px;
          .text {
            font-size: 16px;
          }
          .right {
            align-items: center;
            i {
              margin-left: 10px;
            }
            .bewdao {
              width: 63px;
              height: 32px;
            }
            .daochu {
              background-color: #1890ff;
              color: #fff;
              border: none;
              border-radius: 3px;
            }
          }
        }
      }
      .dialog {
        .title {
          font-size: 28px;
          margin-bottom: 30px;
        }
        .text {
          font-size: 12px;
          color: #3b8eea;
        }
      }
    }
  }
}
::v-deep textarea {
  font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
}
::v-deep .el-select {
  width: 100%;
}
::v-deep .el-input {
  height: 32px;
}
::v-deep .el-input__inner {
  height: 32px;
}
::v-deep .el-input__icon {
  line-height: 1;
}
.el-select-dropdown__item {
  padding-left: 10px;
}
::v-deep .el-date-editor {
  width: 100%;
}

.el-form-item {
  margin-bottom: 20px;
}
.button {
  width: 63px;
  height: 32px;
  margin-right: 5px;
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 3px;
}
.chaxun {
  background-color: #1890ff;
  color: #fff;
}
::v-deep .el-range-separator {
  line-height: 25px;
}
.timeTitle {
  height: 50px;
}

.dropdown-list {
  padding: 0;
  text-align: center;
  width: 50px;
}

.change-type {
  width: 100px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  border-radius: 4px;
  background-color: rgba(255, 255, 255, 1);
  font-size: 14px;
  color: #606266;
  margin-right: 10px;
}

.node-img {
  width: 16px;
  height: 16px;
  margin-right: 5px;
  vertical-align: bottom;
}
</style>
